home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Input / IFOParser / IFOParser.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-08  |  6.9 KB  |  296 lines

  1. /* 
  2.  *  IFOParser.cpp 
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000  ultraflask@yahoo.com
  5.  *                 
  6.  *
  7.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  8.  *    
  9.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  10.  *  it under the terms of the GNU General Public License as published by
  11.  *  the Free Software Foundation; either version 2, or (at your option)
  12.  *  any later version.
  13.  *   
  14.  *  FlasKMPEG is distributed in the hope that it will be useful,
  15.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *  GNU General Public License for more details.
  18.  *   
  19.  *  You should have received a copy of the GNU General Public License
  20.  *  along with GNU Make; see the file COPYING.  If not, write to
  21.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  22.  *
  23.  */
  24.  
  25. #include "IFOParser.h"
  26. #include <stdio.h>
  27.  
  28. #include <io.h>
  29. #include <stdlib.h>
  30.  
  31. #include <sys/types.h>
  32. //#include <unistd.h>
  33. #include <fcntl.h>
  34. #include "..\..\Misc\CArray.h"
  35. #include "ifo.h"
  36. #include "misc.h"
  37.  
  38. char version[] = "V0.1.1";
  39. extern void ifo_print_audiosub (u_char *ptr);
  40. extern void ifoPrintSPU        (ifo_spu_t *spu, u_int num);
  41. extern void ifoPrintAudio    (ifo_audio_t *audio, u_int num);
  42. extern void ifoPrintTMT        (ifo_t *ifo);
  43. extern void ifoPrint_ptt (ifo_ptt_t *ptt);
  44. extern void ifoPrint_vts_vobu_addr_map (ifo_t *ifo);
  45. extern void ifoPrint_vtsm_vobu_addr_map (ifo_t *ifo);
  46. extern void ifoPrint_vts_cell_addr (ifo_t *ifo);
  47. extern void ifoPrint_vtsm_cell_addr (ifo_t *ifo);
  48. extern void ifoPrint_title_pgci (ifo_t *ifo);
  49. extern void ifoPrintToast (u_char *toast);
  50. extern void ifoPrint_menu_pgci (ifo_t *ifo);
  51. extern void ifoPrint_pgc_cmd (u_char *pgc_ptr);
  52. //////////////////////////////////////////////////////////////////////
  53. // Construction/Destruction
  54. //////////////////////////////////////////////////////////////////////
  55. CIFOParser *IFOGlobal;
  56.  
  57. CIFOParser::CIFOParser()
  58. {
  59.    IFOGlobal = this;
  60.    ifo     = NULL;
  61. }
  62.  
  63. CIFOParser::~CIFOParser()
  64. {
  65.     UnLoad();
  66. }
  67.  
  68. int CIFOParser::Load(char *file)
  69. {
  70.     int i,j;
  71.  
  72.     //Initializing...
  73.     this->AudioCount       = 0;
  74.     this->SubpicCount      = 0;
  75.     this->fatal_error_flag = 0;
  76.  
  77.     if ((fd = open (file, O_RDONLY|_O_BINARY)) < 0) {
  78.         return 0;    
  79.     }
  80.     if (!(ifo = ifoOpen (fd, 0))) {
  81.         return 0;
  82.     }
  83.     ifoPrintVideo (ifo->data[ID_MAT] + IFO_OFFSET_VIDEO);
  84.  
  85.     if (!ifoIsVTS (ifo)) {
  86.         char *ptr;
  87.         int num;
  88.  
  89.         if ((num = ifoGetAudio ((char *)ifo->data[ID_MAT] + IFO_OFFSET_AUDIO, &ptr)) > 0)
  90.             ifoPrintAudio ((ifo_audio_t *)ptr, num);
  91.             if(fatal_error_flag){
  92.                 ifoClose (ifo);
  93.                 close(fd);
  94.                 return 0;
  95.             }
  96.  
  97.         if ((num = ifoGetSPU ((char *)ifo->data[ID_MAT] + IFO_OFFSET_SUBPIC, &ptr)) > 0)
  98.             ifoPrintSPU ((ifo_spu_t *)ptr, num);
  99.             if(fatal_error_flag){
  100.                 ifoClose (ifo);
  101.                 close(fd);
  102.                 return 0;
  103.             }
  104.  
  105.         //ifoPrintSPU (ifoGetSPU (ifo->data[ID_MAT] + IFO_OFFSET_SUBPIC));
  106.  
  107.         ifoPrintTMT (ifo);
  108.  
  109.         ifoPrint_ptt (ifo_get_ptt (ifo));
  110.     }
  111.  
  112.     if (!ifoIsVMG (ifo)) {
  113.         ifo_print_audiosub (ifo->data[ID_TMT]);
  114.         ifoPrintToast (ifo->data[ID_PTT]);
  115.  
  116. //        ifoPrint_ptt (ifo_get_ptt (ifo));
  117.     }
  118.  
  119.     ifoPrint_title_pgci (ifo);
  120.     if(fatal_error_flag){
  121.         ifoClose (ifo);
  122.         close(fd);
  123.         return 0;
  124.     }
  125. /*    ifoPrint_menu_pgci (ifo);
  126.     ifoPrint_vtsm_cell_addr (ifo);
  127.     ifoPrint_vtsm_vobu_addr_map (ifo);
  128. */
  129.     ifoPrint_vts_cell_addr (ifo);
  130. /*    ifoPrint_vts_vobu_addr_map (ifo);
  131. */
  132.     ifoClose (ifo);
  133.     close(fd);
  134. /*    for(i=0; i<PGCCount; i++)
  135.         for(j=0; j<first[i].vob_span_count; j++){
  136.             if( first[i].vs[j].start >
  137.         }
  138. */
  139.     // IFO Parsing is finished
  140.     // Perform miscellaneous routines
  141.     // Set all PGCS parsed flag to 0
  142.     if(pgcs.GetCount()<=0)
  143.         return 0;
  144.  
  145.     for(i=0; i<pgcs.GetCount(); i++)
  146.         for(j=0; j<pgcs[i].chain_cells.GetCount(); j++)
  147.             pgcs[i].chain_cells[j].parsed = 0;
  148.  
  149.     int angle_count;
  150.     // for each pgc
  151.     PGCs.SetArraySize( pgcs.GetCount() );
  152.     for(i=0; i<pgcs.GetCount(); i++)
  153.     {
  154.         angle_count = 0;
  155.         while(1){
  156.             // Find the first item that hasn't been parsed
  157.             j=0;
  158.             while( j != pgcs[i].chain_cells.GetCount() )  
  159.             {
  160.                 if (pgcs[i].chain_cells[j].parsed==0)
  161.                     break;
  162.                 j++;
  163.             }
  164.             if( j==pgcs[i].chain_cells.GetCount() )
  165.                 // All possible angles were found
  166.                 break;
  167.             // j, stores the first not parsed item
  168.             // Create a new pgc.
  169.             PGCs[i].BuiltPGC.SetArraySize( angle_count + 1 );
  170.                         
  171.             // BuildPGCAngle
  172.             while(1)
  173.             {
  174.                 RenderCell(i, angle_count, j);
  175.                 // Set cell as parsed
  176.                 pgcs[i].chain_cells[j].parsed=1;
  177.                 // Find first cell whose start point
  178.                 // is greater than the current cell end point
  179.                 int current_cell = j;
  180.                 int    next_cell = j+1;
  181.  
  182.                 while( next_cell != pgcs[i].chain_cells.GetCount() )  
  183.                 {
  184.                     if (pgcs[i].chain_cells[next_cell].start >
  185.                         pgcs[i].chain_cells[current_cell].end)
  186.                         break;
  187.                     next_cell++;
  188.                 }
  189.                 if( next_cell==pgcs[i].chain_cells.GetCount() )
  190.                     // If we've reached the top
  191.                     break;
  192.                 j = next_cell;
  193.             }
  194.             PGCs[i].BuiltPGC[angle_count].chain_time = pgcs[i].chain_time;
  195.             angle_count++;
  196.         }
  197.     }
  198.     
  199.     return 1;
  200. }
  201. int CIFOParser::RenderCell(int pgc_number, int angle, int cell_to_render)
  202. {
  203.     int vobid, cellid,i;
  204.     CArr<TSpan> cell_spans;
  205.  
  206.      vobid = pgcs[pgc_number].chain_cells[cell_to_render].vobid;
  207.     cellid = pgcs[pgc_number].chain_cells[cell_to_render].cellid;
  208.  
  209.     GetCellSpans( cell_spans, vobid, cellid );
  210.     for(i=0; i<cell_spans.GetCount(); i++)
  211.     {
  212.         PGCs[pgc_number].BuiltPGC[angle].playinfo.AddItem( &cell_spans[i] );
  213.     }
  214.     return 1;
  215. }
  216.  
  217. int CIFOParser::GetCellSpans(CArr<TSpan>& cell_spans, int vobid, int cellid)
  218. {
  219.     int i;
  220.     for(i=0; i<cell_address.GetCount(); i++)
  221.     {
  222.         if(cell_address[i].vobid  == vobid 
  223.         && cell_address[i].cellid == cellid)
  224.             break;
  225.     }
  226.     cell_spans = cell_address[i].pos;
  227.     return 1;
  228. }
  229.  
  230.  
  231. int CIFOParser::UnLoad(){
  232.     return 1;
  233. }
  234. int CIFOParser::GetAudioCount()
  235. {
  236.     return this->AudioCount;
  237. }
  238.  
  239. char *CIFOParser::GetAudioID(int id)
  240. {
  241.     if(id >= this->AudioCount)
  242.         return NULL;
  243.     return this->AudioID[id];
  244. }
  245.  
  246. int CIFOParser::GetSubpicCount()
  247. {
  248.     return this->SubpicCount;
  249. }
  250.  
  251. int CIFOParser::GetSubpicCLUT(TPGC *pgc, char *clut)
  252. {
  253.     return 0;
  254. }
  255.  
  256. int CIFOParser::GetPGCCount()
  257. {
  258.     return this->pgcs.GetCount();
  259. }
  260.  
  261. TPGC *CIFOParser::GetPGC(int id)
  262. {
  263. /*    if(id >= this->PGCCount)
  264.         return NULL;*/
  265.     return NULL;
  266. }
  267.  
  268. unsigned int CIFOParser::GetPGCTime(TPGC *pgc)
  269. {
  270.     return 0;
  271. }
  272.  
  273. char *CIFOParser::GetSubpicID(int id)
  274. {
  275.     if(id >= this->SubpicCount)
  276.         return NULL;
  277.     return this->SubpidID[id];
  278. }
  279.  
  280. TCellAdressInfo& TCellAdressInfo::operator =(TCellAdressInfo& right)
  281. {
  282.     this->cellid = right.cellid;
  283.     pos = right.pos;
  284.     this->vobid  = right.vobid;
  285.     return *this;
  286. }
  287.  
  288. TPGC& TPGC::operator =(TPGC& right)
  289. {
  290.     this->chain_cells = right.chain_cells;
  291.     this->chain_time  = right.chain_time;
  292.     memcpy( clut, right.clut, sizeof(char)*16*4 );
  293.  
  294.     return *this;
  295. }
  296.